import { db, Sequelize, foreignKeyType, validator } from '../../infrastructure/db';
const crypto = require('crypto');

interface UserAttributes {
    id?: string;
    passwordHash?: string;
    username?: string;
    openid?: string;
    unionId?: string;
    JSONSchmea?: string;
    identity?: string;
}

interface UserInstance extends Sequelize.Instance<UserAttributes>, UserAttributes {
    dataValues: UserAttributes;
}

interface UserModel extends Sequelize.Model<UserInstance, UserAttributes> { }

const User: UserModel = db.define<UserInstance, UserAttributes>('User', {
    id: {
        comment: '用户id',
        type: Sequelize.UUID,
        defaultValue: Sequelize.UUIDV4,
        unique: true,
        primaryKey: true,
    },
    username: {
        comment: '用户名',
        type: Sequelize.STRING,
    },
    passwordHash: {
        comment: '加密后的登录密码',
        type: Sequelize.STRING,
    },
    openid: {
        comment: '微信公众平台openid',
        type: Sequelize.STRING,
    },
    unionId: {
        comment: '微信平台用户唯一Id',
        type: Sequelize.STRING
    },
    JSONSchmea: {
        comment: '微信平台用户个人信息',
        type: Sequelize.STRING
    },
    identity: {
        comment: '身份',
        type: Sequelize.ENUM('customer', 'service')
    }
}, {
        classMethods: {
            associate: (models) => {

            }
        }
    }
);

interface AppointmentAttributes {
    id?: string;
    name?: string;
    phone?: string;
    gradeType?: string;
    grade?: string;
    subject?: string;
    referral?: string;
}

interface AppointmentInstance extends Sequelize.Instance<AppointmentAttributes>, AppointmentAttributes {
    dataValues: AppointmentAttributes;
}

interface AppointmentModel extends Sequelize.Model<AppointmentInstance, AppointmentAttributes> { }

const Appointment: AppointmentModel = db.define<AppointmentInstance, AppointmentAttributes>('Appointment', {
    id: {
        comment: '预约记录id',
        type: Sequelize.UUID,
        defaultValue: Sequelize.UUIDV4,
        unique: true,
        primaryKey: true,
    },
    name: {
        comment: '姓名',
        type: Sequelize.STRING,
        allowNull: false
    },
    phone: {
        comment: '手机号码',
        type: Sequelize.STRING,
        allowNull: false,
    },
    gradeType: {
        comment: '小初高',
        type: Sequelize.STRING,
        allowNull: false,
    },
    grade: {
        comment: '年级',
        type: Sequelize.STRING,
        allowNull: false
    },
    subject: {
        comment: '科目',
        type: Sequelize.STRING,
        allowNull: false
    },
    referral: {
        comment: '推荐人',
        type: Sequelize.STRING,
    }
});

export {
    User,
    Appointment
}